<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <!--移动端浏览 viewport移动端浏览   width表示可视区域 initial-scale首次浏览 无缩放-->
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <Title>博客管理</Title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.css">
    <link rel="stylesheet" href="../../static/css/me.css" th:href="@{/css/me.css}">
</head>

<body>
    <!-- 导航 -->
    <nav th:replace="admin/Afragments::menu(1)"></nav>

    <div class="ui attached secondary pointing teal menu basic me-border-hidden">
        <div class="ui container">
            <div class="right menu basic">
                <a href="#" th:href="@{/admin/blogs}" class="active item">列表</a>
                <a href="#" th:href="@{/admin/blogs/input}" class="item">发布</a>
            </div>
        </div>
    </div>
   
        
    

    <!-- 中间内容 -->
    <div class="me-padded-tb-large">
        <!-- container可以自动响应布局 -->
        <div class="ui container">
            
            <div  class="ui form">
                <input type="hidden" name="page" >
                <div class="inline fields">
                    <div class="field">
                        <input type="text" name="title" placeholder="标题">
                    </div>
                    <div class="field">
                        <div class="ui selection dropdown">
<!--                            一个隐藏框 方便传参数-->
                            <input type="hidden" name="typeId">
                            <i class="dropdown icon"></i>
                            <div class="default text">分类</div>
                            <div class="menu">
                                <div th:each="type : ${types}" class="item" data-value="1" th:data-value="${type.id}" th:text="${type.name}">算法</div>
                                <!--/*-->
                                <div class="item" data-value="2">springboot</div>
                                <!--*/-->
                            </div>
                        </div>
                    </div>
                    <!-- 推荐的复选框 -->
                    <div class="field ">
                        <div class="ui checkbox">
                            <input type="checkbox" name="recommend" id="recommend">
                            <!-- for 和 id 相关联 -->
                            <label for="recommend">
                             <p style="color: white;">
                                推荐
                             </p>   
                            </label>
                        </div>
                    </div>
                    <!-- 查询 -->
                    <div class="field">
                        <button  type="button" id="search-btn"  class="ui teal  basic button"><i class="search icon"></i>搜索</button>
                    </div>
                    
                </div>
            </div>
            <div id="table-container">
                <table th:fragment="blogList" class="ui table ">
                    <thead>
                    <tr>
                        <th></th>
                        <th>标题</th>
                        <th>类型</th>
                        <th>推荐</th>
                        <th>状态</th>
                        <th>更新时间</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr th:each="blog,iterStat : ${page.getRecords()}">
                        <td th:text="${iterStat.count}">1</td>
                        <td th:text="${blog.title}">线段树详解</td>
                        <td th:text="${blog.getTypeName()}">数据结构</td>
                        <td th:text="${blog.recommend} ? '是':'否'">是</td>
                        <td th:text="${blog.published} ? '发布':'草稿'">草稿</td>
                        <td th:text="${#dates.format(blog.updateTime, 'yyyy-MM-dd HH:mm:ss')}">2020-03-22 10:58</td>
                        <td>
                            <a href="#" th:href="@{/admin/blogs/{id}/input(id=${blog.id})}" class="ui  teal  button">编辑</a>
                            <a href="#" th:href="@{/admin/blogs/{id}/delete(id=${blog.id})}" class="ui  red  button">删除</a>
                        </td>
                    </tr>
                    </tbody>
                    <tfoot>
                    <tr>
                        <!-- colspan是合并单元格 -->
                        <th colspan="7">
                            <div class="ui  pagination menu" th:if="${page.pages>1}">
                                <a onclick="page(this)" th:attr="data-page=${page.getCurrent()}-1" class="item" th:if="${page.hasPrevious()}">上一页</a>
                                <a onclick="page(this)" th:attr="data-page=${page.getCurrent()}+1" class=" item" th:if="${page.hasNext()}">下一页</a>
                            </div>

                            <a href="" th:href="@{/admin/blogs/input}" class="ui right floated teal button large">新增</a>
                        </th>
                    </tr>
                    </tfoot>
                </table>

                <div class="ui success message" th:unless="${#strings.isEmpty(message)}">
                    <i class="close icon"></i>
                    <div class="header">提示：</div>
                    <p th:text="${message}">恭喜，操作成功！</p>
                </div>

            </div>

        </div>

    </div>

    <!-- 底部栏 -->

    <footer th:fragment="footer" class="ui inverted vertical segment me-padded-tb-massive">
        <div class="ui center aligned container">
            <div class="ui inverted divided stackable grid">
                <div class="three wide column">
                    <div class="ui inverted link list">
                        <div class="item">
                            <img src="../../static/image/wechat.png" alt="" class="ui rounded image" style="width: 110px">
                        </div>
                    </div>
                </div>
                <div class="three wide column">
                    <h4 class="ui inverted header">最新博客</h4>
                    <div class="ui inverted link list">
                        <a href="#" class="item">算法竞赛进阶指南 </a>
                        <a href="#" class="item">分布式协调系统 zookeeper</a>
                        <a href="#" class="item">消息队列 kafka</a>
                    </div>
                </div>
                <div class="three wide column">
                    <h4 class="ui inverted header">联系方式</h4>
                    <div class="ui inverted link list">
                        <a href="#" class="item">Email:yrq991121@163.com</a>
                        <a href="#" class="item">QQ:1193700079</a>
                        <a href="#" class="item">Github</a>
                    </div>
                </div>
                <div class="seven wide column">
                    <h4 class="ui inverted header">网站简介</h4>
                    <p>我的个人技术博客，练习一下Springboot，对于后端技术主要是操作系统和数据库这一块的理论知识，做网页纯属技术爱好，前端技术主要是UI设计，用户交互，要具备优秀的艺术欣赏水平，偶尔接私活，需要的微信扫码加我联系
                    </p>
                </div>
            </div>
            <div class="ui inverted section divider">
            </div>
            <p class="m-text-lined m-text-spaced m-text-thin m-opacity-mini">Copyright @ 2020 - 2021 Blog_Daniel
                Designed by yrq
                <br>
                来自华北理工大学的技术宅
            </p>
        </div>


    </footer>



    <script src="http://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.js"></script>
<!--    <script src="https://cdn.jsdelivr.net/npm/jquery@3.2/dist/jquery.min.js"></script>-->

    <script>
        $('.menu.toggle').click(function () {
            $('.me-item').toggleClass('me-mobile-hide');
        });

        $('.ui.user.dropdown').dropdown({
            on: 'hover'
        });

        $('.ui.selection.dropdown').dropdown({
            on: 'hover'
        });

        //消息提示关闭初始化
        $('.message .close')
            .on('click', function () {
                $(this)
                    .closest('.message')
                    .transition('fade');
            });


        function page(obj) {
            $("[name='page']").val($(obj).data("page"));
            loaddata();
        }

        $('#search-btn').on('click',function(){
            $("[name='page']").val(0);
                loaddata();
        });

        function loaddata() {
            $("#table-container").load("/admin/blogs/search",{
                title : $("[name='title']").val(),
                typeId : $("[name='typeId']").val(),
                recommend : $("[name='recommend']").prop('checked'),
                page : $("[name='page']").val()
            });
        };

    </script>
</body>

</html>